using Microsoft.EntityFrameworkCore;
using System.Reflection;
using TraceabilityApp_Api;
using TraceabilityApp_Infrastructure;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(x=>x.IncludeXmlComments(AppContext.BaseDirectory+ "TraceabilityApp-Api.xml",true));

builder.Services.AddDbContext<MyDbContext>(x =>
{
    x.UseSqlServer(builder.Configuration["ConnectionStrings:ConStr"]);
});
builder.Services.AddMediatR(x=>x.RegisterServicesFromAssemblies(Assembly.GetExecutingAssembly()));
builder.Services.AddAutoMapper(typeof(Mappers));
builder.Services.AddScoped(typeof(IBase<>),typeof(Base<>));



var app = builder.Build();
app.UseCors(x=>x.AllowAnyHeader().AllowAnyOrigin().AllowAnyMethod());
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}
app.UseStaticFiles();
app.UseAuthorization();

app.MapControllers();

app.Run();
